<?php 
	//timer pengecekan load page...
	include("inc/timer.php");
	$_start_timer = get_microtime();
	 
	//check protect1 jika session da tidak valid, balikin ke index.php
	//jika valid y biarin saja
	
	require_once("protect1.php");
	require_once("inc/connect.php");
	require_once("inc/settings.php");

	
	//pindahkan ke lokal variable
	$_nrp = $reg_uname;
	$_semester = $_global_settings['semester']->value;
	$_tahun_ajaran = $_global_settings['tahun_ajaran']->value;
	$_level_settings = getLevelSettings($reg_level, $pdo);
	
	// $pilih=mysql_select_db("uwika_krs",$conn);
	//$pdo->query("USE uwika_krs");

	$sql = "SELECT nama FROM biodata WHERE nrp = :reg_uname ";
	$stmt_mahasiswa = $pdo->prepare($sql);
	$stmt_mahasiswa->execute(array(':reg_uname' => $_nrp )) or die("ERROR: " . implode(":", $stmt_mahasiswa->errorInfo())); //reg jurusan dari protect1.php
	$_data_mahasiswa = $stmt_mahasiswa->fetch(PDO::FETCH_OBJ);
	
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Home !</title>
<link rel="stylesheet" type="text/css" href="css/reset_main.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<style type="text/css">
	body{ behavior:url(cssHoverFix.htc);}
	#div a { normal state }
	#div a:hover { alternative state }
</style>
</head>
<body>	
	<header id="main">
		<table id="header">
			<tr>
				<td class="header_logo_small"><a class="header_logo_small" href="#"></a></td>
				<td class="header_announce">
					<marquee style="letter-spacing:1px;marquee-speed:slow;">
						Nilai <strong>UTS</strong> Semester Gasal Periode 2012-2013 sudah keluar *sebagian. 
						Jika anda menemukan Bug / Kritik / Saran, silahkan Laporkan kepada ICT Sesegera mungkin. 
						Terima Kasih.
					</marquee>
				</td>
				<td class="header_user_name"><a class="header_user_name_a" href="#"><?php echo (strlen($_data_mahasiswa->nama) < 15 ? ucwords(strtolower($_data_mahasiswa->nama)) : ucwords(strtolower(substr($_data_mahasiswa->nama,0,15)))."..."); ?></a></td>
				<td class="header_user_photo">
					<a class="header_user_photo_a" href="#">
						<img class="header_user_photo_img" src="images/people/default.gif">
					</a>
				</td>
			</tr>
		</table>
	</header>
	<table class="board">
		<tr>
			<td class="sidebar">
				<div id="navigation">
					<ul class="top-level">
						<?php
//							$basename_url = basename($_SERVER['REQUEST_URI']);
							$basename_url = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
							if(count($_level_settings->menu) > 0){
								foreach($_level_settings->menu as $foreach){
									if ($basename_url == $foreach->url){$clicked = 'class="clicked"';}else{$clicked = '';}
									echo '<li><a href="'.$foreach->url.'" '.$clicked.'>'.$foreach->nama.'</a></li>';
								}
							}else{
								echo '<li><a href="#" class="clicked">Home</a></li>';
							}
						?>
					</ul>
				</div>
			</td>
			<td class="bigbox">
				<div class="banner"></div>
				<div class="content">
				<?php
					/* cek level mahasiswa */
					$sqlstr_checking_level_blokir = "SELECT username, password, level FROM security WHERE username=:uname";
					$stmt_checking_level_blokir = $pdo->prepare($sqlstr_checking_level_blokir);
					$stmt_checking_level_blokir->execute(array(':uname' => $reg_uname));
					//because of php 5.2 $_POST['name'] = $name, that makes me difficult for working -_-
					if($row_checking_level_blokir = $stmt_checking_level_blokir->fetch(PDO::FETCH_OBJ)){
						
						if($row_checking_level_blokir->level != 1){
						?>
							<div class="warning red">
								<label>Account dalam Masa blokir !</label>
								Mohon Maaf, Account Anda untuk sementara waktu ini kami <strong>BLOKIR</strong>
								Jika anda belum menyelesaikan biaya daftar ulang / biaya denda atas keterlambatan KRS, silahkan menghubungi Biro Administrasi Keuangan.
								Terimakasih
							</div>
						<?php
						}
					}
					/* finish */
				?>
				<?php
					//get jurusan & dosen wali
					require_once("inc/function-db.php");
					
					$_jurusan = $function_db->getJurusan(substr($_nrp,0,3),$pdo);
					$_dosen_wali = $function_db->getDosenWali($_nrp,$pdo);

				?>
					
					<div class="warning green border">
						<label>Warm Welcome !</label>
						Selamat datang di KRS-Online, anda dapat mengecek nilai anda dan mengambil/membatalkan mata kuliah untuk periode ini (hanya untuk masa KRS).
					</div>
					<div align="center">
						<table class="data head">
							<tr>
								<td width="15%">Periode</td><td width="2%">:</td><td width="35%"><?php echo $_tahun_ajaran; ?></td><td width="15%">NRP</td><td width="2%">:</td><td width="35%"><?php echo $_nrp; ?></td>
							</tr>
							<tr>
								<td>Semester</td><td>:</td><td><?php echo $_semester; ?></td><td>Nama</td><td>:</td><td><?php echo $_data_mahasiswa->nama; ?></td>
							</tr>
							<tr>
								<td>Program Studi</td><td>:</td><td><?php echo strtoupper($_jurusan->nama_jurusan); ?></td><td>Dosen Wali</td><td>:</td><td><?php echo $_dosen_wali->nama; ?></td>
							</tr>
						</table><br \>
						<table class="data body">
							<thead>
								<th width="4%">No</th><th width="8%">Kode</th><th>Mata Kuliah</th><th>Status</th><th width="7%">SKS</th><th>Act!</th>
							</thead>
							<tbody>
								<?php
								$sql = "SELECT registrasi.kodemk, mk.nama, mk.sks, registrasi.sesi, registrasi.status, registrasi.validasi, registrasi.hari, 
										registrasi.mulaipukul, registrasi.selesaipukul 
										FROM registrasi, mk where sesi=:select_sesi and periode=:select_tahun_ajaran and nrp=:reg_uname and registrasi.kodemk = mk.kodemk";
								$stmt = $pdo->prepare($sql);
								$stmt->execute(array(':select_sesi' => $_semester
														,':select_tahun_ajaran' => $_tahun_ajaran
														,':reg_uname' => $_nrp )); //reg jurusan dari protect1.php
								$count = 1; //using odd php for css2 browser and less
								$jmlsks = 0;
								while($_data = $stmt->fetch(PDO::FETCH_OBJ)){ //fetch data to stdclass object
										if (empty($_data->kodemk)) {
											break;
										}
										$sql2="select hari, mulaipukul, selesaipukul FROM penawaran where kodemk=:kodemk and jurusan=:reg_jurusan";
										$stmt2 = $pdo->prepare($sql2);
										$stmt2->execute(array(':kodemk' => $_data->kodemk
															,':reg_jurusan' => $reg_jurusan )); //reg jurusan dari protect1.php
										$_data2 = $stmt2->fetch(PDO::FETCH_OBJ);
										
										//adding ahref for not supported javascript
										$_data->url = "#";
									?>
										<tr onclick="document.location.href='<?php echo $_data->url;?>';" <?php echo ( ($count % 2) == 0 ? 'class="odd"' : ''); ?>>
											<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $count; ?></a></td>
											<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->kodemk; ?></a></td>
											<td align="left"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->nama; ?></a></td>
											<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->status; ?></a></td>
											<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->sks; ?></a></td>
											<td></td>
										</tr>
									<?php
									$jmlsks += $_data->sks;
									$count++;
								}
								?>
							</tbody>
							<tfoot>
								<tr>
									<td></td><td></td><td></td><td>TOTAL</td><td><span class="sign black big border"><?php echo $jmlsks; ?></span></td><td></td>
								</tr>
							</tfoot>
						</table>
					</div>
				</div>
			</td>
		</tr>
	</table>
	<footer id="main">
	  <div><a href="http://www.widyakartika.ac.id/perpustakaan">Perpustakaan Online</a> | <a href="http://krs.widyakartika.ac.id/">KRS Online</a></div>
	  <div>Copyright &copy; 2012. <a href="http://www.widyakartika.ac.id">Universitas Widya Kartika</a> & <a href="#">Labkom ICT</a> - All rights reserved</div>
		<?php
			$_finish_timer = get_microtime();
			echo 'Page generated in '.round(($_finish_timer - $_start_timer), 4).' seconds.';
		?>
	</footer>
</body>
